package com.ice.work.moment.socket.server;

import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketConfig;
import com.corundumstudio.socketio.SocketIOServer;
import com.ice.work.moment.socket.listener.PushEventListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description 推送websocket
 * @Author DELL
 * @Create 2019-04-17
 * @Since 1.0.0
 */
@Component
@Slf4j
public class PushServer implements InitializingBean {
    @Autowired
    private PushEventListener pushEventListener;

    @Override
    public void afterPropertiesSet() {
        Configuration config = new Configuration();
        config.setPort(30000);

        SocketConfig socketConfig = new SocketConfig();
        socketConfig.setReuseAddress(true);
        socketConfig.setTcpNoDelay(true);
        socketConfig.setSoLinger(0);
        config.setSocketConfig(socketConfig);
        config.setHostname("localhost");

        SocketIOServer server = new SocketIOServer(config);
        server.addListeners(pushEventListener);
        server.start();
        log.info("启动 推送 websocket");
    }
}
